package com.hc.web.struts.action.bbs;

import com.opensymphony.xwork2.Action;
import com.hc.entity.bbs.BBSComponent;
import com.hc.entity.common.Page;
import com.hc.constants.Constant;
import com.hc.web.service.bbs.ClubService;

public class SubBoardAction implements Action {
	private Page page;
	private int pageNo = 1;
	private Integer componentId;
	private BBSComponent subBoard;
	private ClubService clubService;

	public void setComponentId(Integer componentId) {
		this.componentId = componentId;
	}

	public void setClubService(ClubService clubService) {
		this.clubService = clubService;
	}
	
	public String getAncestorPath() {
		return clubService.getAncestorPath(subBoard, subBoard.getComponentName());
	}

	public Page getPage() {
		return page;
	}
	
	public void setPage(Page page) {
		this.page = page;
	}
	
	public void updatePage() {
		page = clubService.findTopicPageByCriteria(Constant.PAGE_SIZE_TOPIC, componentId, pageNo);
	}
	
	public void updateAncestor() {
		BBSComponent board = clubService.getParent(subBoard);
		subBoard.setParent(board);
		
		BBSComponent forum = clubService.getParent(board);
		board.setParent(forum);
	}
	
	public Integer getComponentId() {
		return componentId;
	}
	
	public String execute() {
		subBoard = clubService.getBBSComponentByComponentId(componentId);
		updateAncestor();
		updatePage();
		return "success";
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
}